package cn.edu.dlut.ssdut.foodCredit2012.action;

import java.util.List;

import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;

import cn.edu.dlut.ssdut.foodCredit2012.model.Admin;
import cn.edu.dlut.ssdut.foodCredit2012.model.Basic;
import cn.edu.dlut.ssdut.foodCredit2012.model.BasicCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.Customs;
import cn.edu.dlut.ssdut.foodCredit2012.model.CustomsCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.Export;
import cn.edu.dlut.ssdut.foodCredit2012.model.ExportCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.Finance;
import cn.edu.dlut.ssdut.foodCredit2012.model.FinanceCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.Permission;
import cn.edu.dlut.ssdut.foodCredit2012.model.PermissionCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.PotentialUser;
import cn.edu.dlut.ssdut.foodCredit2012.model.Presentation;
import cn.edu.dlut.ssdut.foodCredit2012.model.PresentationCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.Quality;
import cn.edu.dlut.ssdut.foodCredit2012.model.QualityCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.Tax;
import cn.edu.dlut.ssdut.foodCredit2012.model.TaxCollection;
import cn.edu.dlut.ssdut.foodCredit2012.model.User;
import cn.edu.dlut.ssdut.foodCredit2012.model.UserCollection;
import cn.edu.dlut.ssdut.foodCredit2012.service.AdminService;
import cn.edu.dlut.ssdut.foodCredit2012.service.BasicCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.BasicService;
import cn.edu.dlut.ssdut.foodCredit2012.service.CustomsCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.CustomsService;
import cn.edu.dlut.ssdut.foodCredit2012.service.ExportCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.ExportService;
import cn.edu.dlut.ssdut.foodCredit2012.service.FinanceCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.FinanceService;
import cn.edu.dlut.ssdut.foodCredit2012.service.PermissionCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.PermissionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.PotentialUserService;
import cn.edu.dlut.ssdut.foodCredit2012.service.PresentationCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.PresentationService;
import cn.edu.dlut.ssdut.foodCredit2012.service.QualityCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.QualityService;
import cn.edu.dlut.ssdut.foodCredit2012.service.TaxCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.TaxService;
import cn.edu.dlut.ssdut.foodCredit2012.service.UserCollectionService;
import cn.edu.dlut.ssdut.foodCredit2012.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

public class AdminAction extends ActionSupport{
	private List<PotentialUser> pUserList;
	
	private List<User> userList;
	private List<BasicCollection> basicCList;
	private List<UserCollection> userCList;
	private UserService userS = new UserService();
	private UserCollectionService userCS = new UserCollectionService();
	private PotentialUserService pUserS = new PotentialUserService();
	private AdminService adminS = new AdminService();
	private BasicService basicS = new BasicService();
	private CustomsService customsS = new CustomsService();
	private ExportService exportS = new ExportService();
	private FinanceService financeS = new FinanceService();
	private PresentationService presentationS = new PresentationService();
	private PermissionService permissionS = new PermissionService();
	private TaxService taxS = new TaxService();
	private QualityService qualityS= new QualityService();
	
	private BasicCollectionService basicCS = new BasicCollectionService();
	private CustomsCollectionService customsCS = new CustomsCollectionService();
	private ExportCollectionService exportCS = new ExportCollectionService();
	private FinanceCollectionService financeCS = new FinanceCollectionService();
	private PresentationCollectionService presentationCS = new PresentationCollectionService();
	private PermissionCollectionService permissionCS = new PermissionCollectionService();
	private TaxCollectionService taxCS = new TaxCollectionService();
	private QualityCollectionService qualityCS= new QualityCollectionService();
	
	private Admin admin = new Admin();
	private User user= new User();
	private PotentialUser pUser = new PotentialUser();
	private Basic basic = new Basic();
	private Customs customs = new Customs();
	private Export export = new Export();
	private Finance finance = new Finance();
	private Permission permission = new Permission();
	private Presentation presentation = new Presentation();
	private Tax tax = new Tax();
	private Quality quality = new Quality();
	private UserCollection userC = new UserCollection();
	private BasicCollection basicC = new BasicCollection();
	private CustomsCollection customsC = new CustomsCollection();
	private ExportCollection exportC = new ExportCollection();
	private FinanceCollection financeC = new FinanceCollection();
	private PermissionCollection permissionC = new PermissionCollection();
	private PresentationCollection presentationC = new PresentationCollection();
	private TaxCollection taxC = new TaxCollection();
	private QualityCollection qualityC = new QualityCollection();
	private String licenceID;
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public String login() {
		return SUCCESS;
	}
	public String loginInput()throws Exception{
		
		if(this.adminS.login(admin)){
			this.admin = this.adminS.load(admin);
			return "index";
		}	
		return "login_fail";
	}
	
	public String index() {
		return "index";
	}
	public String userList() {
		this.userList = this.userS.userList();
		for(int i = 0; i< this.userList.size();i++){
			System.out.println(userList.get(i).getName());
		}
		return SUCCESS;
	}
	
	public String userLoad() throws Exception {
		this.user = this.userS.loadByLicenceID(licenceID);
		return SUCCESS;
	}
	
	public String userUpdate() throws Exception{
		this.user = this.userS.loadByLicenceID(licenceID);
		return SUCCESS;
	}
	
	public String userDelete() throws Exception{
		this.user = this.userS.loadByLicenceID(licenceID);
		this.userS.delete(user);
		return "userList";
	}
	
	public String userInfoDelete() throws Exception{
		this.user = this.userS.loadByLicenceID(licenceID);
		this.userS.loadUserInfo(user);
		this.userS.deleteInfo(user);
		return "userInfoList";
	}
	
	public String userUpdateInput() throws Exception{
		this.userS.update(user);
		return SUCCESS;
	}
	
	public String userCollectionList() throws Exception{
		this.userCList = this.userCS.userCollectionList();
		return SUCCESS;
	}
	
	public String userCollectionLoad() throws Exception{
		this.userC = this.userCS.loadByLicenceID(licenceID);
		return SUCCESS;
	}
	
	public String userCollectionToUser() throws Exception{
		this.userC = this.userCS.loadByLicenceID(licenceID);
		
		this.user.setLicenceID(this.userC.getLicenceID());
		this.user.setName(this.userC.getName());
		this.user.setPassWord(this.userC.getPassWord());
		this.user.setRegisterTime(this.userC.getRegisterTime());
		this.userS.add(user);
		this.userCS.delete(userC);
		
		return "userCollectionList";
	}
	public String userCollectionDelete() throws Exception{
		this.userC = this.userCS.loadByLicenceID(licenceID);
		this.userCS.delete(userC);
		return "userCollectionList";
	}
	
	public String userInfoList() throws Exception{
		this.userList = this.userS.userInfoList();
		return SUCCESS;
	}
	
	public String userWithoutInfoList() throws Exception{
		this.userList = this.userS.userWithoutInfoList();
		return SUCCESS;
	}
	
	public String userWithoutInfoDelete() throws Exception{
		this.user= this.userS.loadByLicenceID(licenceID);
		this.userS.delete(user);
		return "userWithoutInfoList";
	}
	
	public String userInfoLoad() throws Exception{
		
		this.basic = this.basicS.loadByLicenceID(licenceID);
		this.customs = this.customsS.loadByLicenceID(licenceID);
		this.export = this.exportS.loadByLicenceID(licenceID);
		this.finance = this.financeS.loadByLicenceID(licenceID);
		this.permission = this.permissionS.loadByLicenceID(licenceID);
		this.presentation = this.presentationS.loadByLicenceID(licenceID);
		this.tax =this.taxS.loadByLicenceID(licenceID);
		this.quality = this.qualityS.loadByLicenceID(licenceID);
		
		return SUCCESS;
	}
	
	public String userInfoUpdate() throws Exception{
		this.basic = this.basicS.loadByLicenceID(licenceID);
		this.customs = this.customsS.loadByLicenceID(licenceID);
		this.export = this.exportS.loadByLicenceID(licenceID);
		this.finance = this.financeS.loadByLicenceID(licenceID);
		this.permission = this.permissionS.loadByLicenceID(licenceID);
		this.presentation = this.presentationS.loadByLicenceID(licenceID);
		this.tax =this.taxS.loadByLicenceID(licenceID);
		this.quality = this.qualityS.loadByLicenceID(licenceID);
		return SUCCESS;
	}
	
	public String userInfoUpdateInput() throws Exception{
		
		
		basic.setLicenceID(licenceID);
		customs.setLicenceID(licenceID);
		export.setLicenceID(licenceID);
		finance.setLicenceID(licenceID);
		permission.setLicenceID(licenceID);
		presentation.setLicenceID(licenceID);
		tax.setLicenceID(licenceID);
		quality.setLicenceID(licenceID);
		
		this.basicS.update(this.basic);
		this.customsS.update(customs);
		this.exportS.update(export);
		this.financeS.update(finance);
		this.permissionS.update(permission);
		this.presentationS.update(presentation);
		this.taxS.update(tax);
		this.qualityS.update(quality);
		
		return "userInfoList";
	}
	
	public String potentialUserAdd() {
		return SUCCESS;
	}
	
	public String potentialUserAddInput()throws Exception{
		if(!this.pUserS.isPotentialUser(pUser) && !this.pUserS.isUser(pUser)){
			this.pUserS.add(pUser);
			return "potentialUserList";
		}
		return "potentialUser";
	}
	
	public String potentialUserDelete() throws Exception{
		this.pUser = this.pUserS.loadByLicenceID(licenceID);
		this.pUserS.delete(pUser);
		return "potentialUserList";
		
	}
	
	public String potentialUserList() {
		
		this.pUserList = this.pUserS.userList();
		return SUCCESS;
	}
	
	public String userCollectionInfoList() throws Exception{
		
		this.basicCList = this.basicCS.basicCList();
		return SUCCESS;
	}
	
	public String userCollectionInfoLoad() throws Exception{
		
		this.basicC = this.basicCS.loadByLicenceID(licenceID);
		this.customsC =this.customsCS.loadByLicenceID(licenceID);
		this.exportC = this.exportCS.loadByLicenceID(licenceID);
		this.financeC = this.financeCS.loadByLicenceID(licenceID);
		this.permissionC = this.permissionCS.loadByLicenceID(licenceID);
		this.presentationC = this.presentationCS.loadByLicenceID(licenceID);
		this.taxC = this.taxCS.loadByLicenceID(licenceID);
		this.qualityC = this.qualityCS.loadByLicenceID(licenceID);
		
		return SUCCESS;
	}
	
	public String userCollectionInfoToUser() throws Exception{
		
		this.basicC = this.basicCS.loadByLicenceID(licenceID);
		this.customsC = this.customsCS.loadByLicenceID(licenceID);
		this.exportC = this.exportCS.loadByLicenceID(licenceID);
		this.financeC = this.financeCS.loadByLicenceID(licenceID);
		this.permissionC = this.permissionCS.loadByLicenceID(licenceID);
		this.presentationC = this.presentationCS.loadByLicenceID(licenceID);
		this.taxC = this.taxCS.loadByLicenceID(licenceID);
		this.qualityC = this.qualityCS.loadByLicenceID(licenceID);
		
		this.basic = this.basicS.basicCollectionToBasic(basicC);
		this.customs = this.customsS.customsCollectionToCostoms(customsC);
		this.export = this.exportS.exportCollectionToExport(exportC);
		this.finance = this.financeS.financeCollectionToFinance(financeC);
		this.permission = this.permissionS.permissionCollectionToPremission(permissionC);
		this.presentation = this.presentationS.presentationCollectionToPresentation(presentationC);
		this.tax = this.taxS.taxCollectionToTax(taxC);
		this.quality = this.qualityS.qualityCollectionToQuality(qualityC);
		
		this.user.setLicenceID(licenceID);
		this.user.setBasic(basic);
		this.user.setCustoms(customs);
		this.user.setExport(export);
		this.user.setFinance(finance);
		this.user.setPermission(permission);
		this.user.setPresentation(presentation);
		this.user.setTax(tax);
		this.user.setQuality(quality);
		
		this.userS.addInfo(user);
		
		if(this.userS.isUser(user))
		{
		this.basicCS.delete(basicC);
		this.customsCS.delete(customsC);
		this.exportCS.delete(exportC);
		this.financeCS.delete(financeC);
		this.permissionCS.delete(permissionC);
		this.presentationCS.delete(presentationC);
		this.taxCS.delete(taxC);
		this.qualityCS.delete(qualityC);
		}
		
		return "userCollectionInfoList";
	}
	
	public String userCollectionInfoDelete() throws Exception{
		
		this.basicC = this.basicCS.loadByLicenceID(licenceID);
		this.customsC = this.customsCS.loadByLicenceID(licenceID);
		this.exportC = this.exportCS.loadByLicenceID(licenceID);
		this.financeC = this.financeCS.loadByLicenceID(licenceID);
		this.permissionC = this.permissionCS.loadByLicenceID(licenceID);
		this.presentationC = this.presentationCS.loadByLicenceID(licenceID);
		this.taxC = this.taxCS.loadByLicenceID(licenceID);
		this.qualityC = this.qualityCS.loadByLicenceID(licenceID);
		
		this.basicCS.delete(basicC);
		this.customsCS.delete(customsC);
		this.exportCS.delete(exportC);
		this.financeCS.delete(financeC);
		this.permissionCS.delete(permissionC);
		this.presentationCS.delete(presentationC);
		this.taxCS.delete(taxC);
		this.qualityCS.delete(qualityC);
		
		return "userCollectionList";
	}
	
	
	
	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	public UserService getUserS() {
		return userS;
	}

	public void setUserS(UserService userS) {
		this.userS = userS;
	}

	public AdminService getAdminS() {
		return adminS;
	}

	public void setAdminS(AdminService adminS) {
		this.adminS = adminS;
	}
	public Admin getAdmin() {
		return admin;
	}
	public void setAdmin(Admin admin) {
		this.admin = admin;
	}
	public String getLicenceID() {
		return licenceID;
	}
	public void setLicenceID(String licenceID) {
		this.licenceID = licenceID;
	}
	public List<UserCollection> getUserCList() {
		return userCList;
	}
	public void setUserCList(List<UserCollection> userCList) {
		this.userCList = userCList;
	}
	public UserCollection getUserC() {
		return userC;
	}
	public void setUserC(UserCollection userC) {
		this.userC = userC;
	}
	public UserCollectionService getUserCS() {
		return userCS;
	}
	public void setUserCS(UserCollectionService userCS) {
		this.userCS = userCS;
	}
	public BasicService getBasicS() {
		return basicS;
	}
	public void setBasicS(BasicService basicS) {
		this.basicS = basicS;
	}
	public CustomsService getCustomsS() {
		return customsS;
	}
	public void setCustomsS(CustomsService customsS) {
		this.customsS = customsS;
	}
	public ExportService getExportS() {
		return exportS;
	}
	public void setExportS(ExportService exportS) {
		this.exportS = exportS;
	}
	public FinanceService getFinanceS() {
		return financeS;
	}
	public void setFinanceS(FinanceService financeS) {
		this.financeS = financeS;
	}
	public PresentationService getPresentationS() {
		return presentationS;
	}
	public void setPresentationS(PresentationService presentationS) {
		this.presentationS = presentationS;
	}
	public PermissionService getPermissionS() {
		return permissionS;
	}
	public void setPermissionS(PermissionService permissionS) {
		this.permissionS = permissionS;
	}
	public TaxService getTaxS() {
		return taxS;
	}
	public void setTaxS(TaxService taxS) {
		this.taxS = taxS;
	}
	public QualityService getQualityS() {
		return qualityS;
	}
	public void setQualityS(QualityService qualityS) {
		this.qualityS = qualityS;
	}
	public Basic getBasic() {
		return basic;
	}
	public void setBasic(Basic basic) {
		this.basic = basic;
	}
	public Customs getCustoms() {
		return customs;
	}
	public void setCustoms(Customs customs) {
		this.customs = customs;
	}
	public Export getExport() {
		return export;
	}
	public void setExport(Export export) {
		this.export = export;
	}
	public Finance getFinance() {
		return finance;
	}
	public void setFinance(Finance finance) {
		this.finance = finance;
	}
	public Permission getPermission() {
		return permission;
	}
	public void setPermission(Permission permission) {
		this.permission = permission;
	}
	public Presentation getPresentation() {
		return presentation;
	}
	public void setPresentation(Presentation presentation) {
		this.presentation = presentation;
	}
	public Tax getTax() {
		return tax;
	}
	public void setTax(Tax tax) {
		this.tax = tax;
	}
	public Quality getQuality() {
		return quality;
	}
	public void setQuality(Quality quality) {
		this.quality = quality;
	}
	public BasicCollection getBasicC() {
		return basicC;
	}
	public void setBasicC(BasicCollection basicC) {
		this.basicC = basicC;
	}
	public CustomsCollection getCustomsC() {
		return customsC;
	}
	public void setCustomsC(CustomsCollection customsC) {
		this.customsC = customsC;
	}
	public ExportCollection getExportC() {
		return exportC;
	}
	public void setExportC(ExportCollection exportC) {
		this.exportC = exportC;
	}
	public FinanceCollection getFinanceC() {
		return financeC;
	}
	public void setFinanceC(FinanceCollection financeC) {
		this.financeC = financeC;
	}
	public PermissionCollection getPermissionC() {
		return permissionC;
	}
	public void setPermissionC(PermissionCollection permissionC) {
		this.permissionC = permissionC;
	}
	public PresentationCollection getPresentationC() {
		return presentationC;
	}
	public void setPresentationC(PresentationCollection presentationC) {
		this.presentationC = presentationC;
	}
	public TaxCollection getTaxC() {
		return taxC;
	}
	public void setTaxC(TaxCollection taxC) {
		this.taxC = taxC;
	}
	public QualityCollection getQualityC() {
		return qualityC;
	}
	public void setQualityC(QualityCollection qualityC) {
		this.qualityC = qualityC;
	}
	public BasicCollectionService getBasicCS() {
		return basicCS;
	}
	public void setBasicCS(BasicCollectionService basicCS) {
		this.basicCS = basicCS;
	}
	public CustomsCollectionService getCustomsCS() {
		return customsCS;
	}
	public void setCustomsCS(CustomsCollectionService customsCS) {
		this.customsCS = customsCS;
	}
	public ExportCollectionService getExportCS() {
		return exportCS;
	}
	public void setExportCS(ExportCollectionService exportCS) {
		this.exportCS = exportCS;
	}
	public FinanceCollectionService getFinanceCS() {
		return financeCS;
	}
	public void setFinanceCS(FinanceCollectionService financeCS) {
		this.financeCS = financeCS;
	}
	public PresentationCollectionService getPresentationCS() {
		return presentationCS;
	}
	public void setPresentationCS(PresentationCollectionService presentationCS) {
		this.presentationCS = presentationCS;
	}
	public PermissionCollectionService getPermissionCS() {
		return permissionCS;
	}
	public void setPermissionCS(PermissionCollectionService permissionCS) {
		this.permissionCS = permissionCS;
	}
	public TaxCollectionService getTaxCS() {
		return taxCS;
	}
	public void setTaxCS(TaxCollectionService taxCS) {
		this.taxCS = taxCS;
	}
	public QualityCollectionService getQualityCS() {
		return qualityCS;
	}
	public void setQualityCS(QualityCollectionService qualityCS) {
		this.qualityCS = qualityCS;
	}
	public List<BasicCollection> getBasicCList() {
		return basicCList;
	}
	public void setBasicCList(List<BasicCollection> basicCList) {
		this.basicCList = basicCList;
	}
	public List<PotentialUser> getpUserList() {
		return pUserList;
	}
	public void setpUserList(List<PotentialUser> pUserList) {
		this.pUserList = pUserList;
	}
	public PotentialUserService getpUserS() {
		return pUserS;
	}
	public void setpUserS(PotentialUserService pUserS) {
		this.pUserS = pUserS;
	}
	public PotentialUser getpUser() {
		return pUser;
	}
	public void setpUser(PotentialUser pUser) {
		this.pUser = pUser;
	}
}
